<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
       <el-form-item label="标签名称" prop="title">
        <el-input v-model="dataForm.title" ></el-input>
      </el-form-item>
      <el-form-item label="状态" >
        <el-radio v-model="dataForm.status" :label="1">正常</el-radio>
        <el-radio v-model="dataForm.status" :label="0">禁用</el-radio>
      </el-form-item>
      <el-form-item label="列表样式" >
        <el-radio-group v-model="dataForm.style">
          <el-radio v-for="(type, index) in typeList" :label="index" :key="index">{{ type }}</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item  label="排序号">
        <el-input-number v-model="dataForm.seq" controls-position="right" :min="0" label="排序号"></el-input-number>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import { Debounce } from '@/utils/debounce'
  export default {
    data () {
      return {
        visible: false,
          typeList: ['一列一个', '一列两个', '一列三个'],
        dataForm: {
          id: 0,
          style: 0,
          title: '',
          status:1,
          seq:0,
          parentId: 0
        },
        dataRule: {
          title: [
            { required: true, message: '标签名称不能为空', trigger: 'blur' },
          ]
        },
       
      }
    },
    created () {
     
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
          if (this.dataForm.id) {
            this.visible = true
            // 修改
            this.$http({
              url: this.$http.adornUrl('/prod/prodTag/info/'+this.dataForm.id),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              console.log(data,'1111');
              this.dataForm=data
            
            })
          } else {
            this.visible = true
           
            this.$nextTick(() => { 
              this.dataForm.style = 0;
            this.dataForm.seq = 0;
            this.dataForm.status = 1;
            this.$refs['dataForm'].resetFields()
          })
          }
        
      },
      // 表单提交
      dataFormSubmit: Debounce(function () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/prod/prodTag`),
              method: this.dataForm.id ? 'put' : 'post',
              data: this.$http.adornData(this.dataForm)
            }).then(({data}) => {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            })
          }
        })
      })
    }
  }
</script>

<style lang="scss">

  .mod-menu {
    .menu-list__input,
    .icon-list__input {
       > .el-input__inner {
        cursor: pointer;
      }
    }
    &__icon-popover {
      max-width: 420px;
    }
    &__icon-list {
      max-height: 180px;
      padding: 0;
      margin: -8px 0 0 -8px;
      > .el-button {
        padding: 8px;
        margin: 8px 0 0 8px;
        > span {
          display: inline-block;
          vertical-align: middle;
          width: 18px;
          height: 18px;
          font-size: 18px;
        }
      }
    }
    .icon-list__tips {
      font-size: 18px;
      text-align: center;
      color: #e6a23c;
      cursor: pointer;
    }
  }
</style>
